#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
template<class InIter1, class InIter2>
InIter1 match(InIter1 start1, InIter1 end1, InIter2 start2)
{
    for(; start1 != end1; ++start1, ++start2){
        if(*start1 == *start2){
            return start1;
        }
    }
    return end1;
}

template<class InIter1, class InIter2, class BinPred>
InIter1 match(InIter1 start1, InIter1 end1, InIter2 start2, BinPred bp)
{
    for(; start1 != end1; ++start1, ++start2){
        if(bp(*start1 ,*start2)){
            return start1;
        }
    }
    return end1;
    
}

int main()
{
    int a1[] = {1, 2, 3, 4, 5};
    std::vector<int> v1(a1, a1 + sizeof(a1) / sizeof(a1[0]));
    std::cout << "array1: ";
    std::copy(v1.begin(), v1.end(), std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;
    
    int a2[] = {9, 8, 3, 2, 1};
    std::vector<int> v2(a2, a2 + sizeof(a2) / sizeof(a2[0]));
    std::cout << "array2: ";
    std::copy(v2.begin(), v2.end(), std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;
    
    std::cout << "match: ";

    std::cout << *match(v1.begin(), v1.end(), v2.begin());
    std::cout << std::endl;
    
    
    
}

    
